<template>
  <div>
    <div>
      <el-row :gutter="24" class="mod-home">
        <el-col :span="8">
          <div class="grid-content bg-purple-1">
            <el-row>
              <el-col :span="10">
                <div style=" text-align: right">配置 <span style="font-size: 26px;">批次数</span></div>
              </el-col>
              <el-col :span="14">
                <div style="line-height: 24px; margin-top: 32px;font-size: 18px;">
                  <span style="font-size: 20px; font-weight: bold; ">{{batchAlive}}</span> / {{batchCount}}
                </div>
                <div style="line-height: 24px;">活跃/总共</div>
              </el-col>
            </el-row>
          </div>
        </el-col>
        <el-col :span="8">
          <div class="grid-content bg-purple-2">
            <el-row>
              <el-col :span="10">
                <div style=" text-align: right">配置 <span style="font-size: 26px;">任务数</span></div>
              </el-col>
              <el-col :span="14">
                <div style="line-height: 24px; margin-top: 32px;font-size: 18px;">
                  <span style="font-size: 20px; font-weight: bold; ">{{taskAlive}}</span> / {{taskCount}}
                </div>
                <div style="line-height: 24px;">活跃/总共</div>
              </el-col>
            </el-row>
          </div>
        </el-col>
        <el-col :span="8">
          <div class="grid-content bg-purple-3">
            <el-row>
              <el-col :span="10">
                <div style=" text-align: right">配置 <span style="font-size: 26px;">执行器数</span></div>
              </el-col>
              <el-col :span="14">
                <div style="line-height: 24px; margin-top: 32px;font-size: 18px;">
                  <span style="font-size: 20px; font-weight: bold; ">{{agentAlive}}</span> / {{agentCount}}
                </div>
                <div style="line-height: 24px;">活跃/总共</div>
              </el-col>
            </el-row>
          </div>
        </el-col>
      </el-row>
    </div>
    <div style="margin-top: 12px;">
      <el-row :gutter="24" class="mod-home">
        <el-col :span="8">
          <div class="grid-content bg-purple-1">
            <el-row>
              <el-col :span="10">
                <div style=" text-align: right">运行 <span style="font-size: 26px;">批次数</span></div>
              </el-col>
              <el-col :span="14">
                <div style="line-height: 24px; margin-top: 48px;font-size: 18px;">
                  <span style="font-size: 20px; font-weight: bold; ">{{todayBatchExec}}</span> <!--/ {{yestDayBatchExec}}-->
                </div>
                <!--<div style="line-height: 24px;">今日/昨日</div>-->
              </el-col>
            </el-row>
          </div>
        </el-col>
        <el-col :span="8">
          <div class="grid-content bg-purple-2">
            <el-row>
              <el-col :span="10">
                <div style=" text-align: right">运行 <span style="font-size: 26px;">任务数</span></div>
              </el-col>
              <el-col :span="14">
                <div style="line-height: 24px; margin-top: 48px;font-size: 18px;">
                  <span style="font-size: 20px; font-weight: bold; ">{{todayTaskExec}}</span> <!--/ {{yestDayTaskExec}}-->
                </div>
                <!--<div style="line-height: 24px;">今日/昨日</div>-->
              </el-col>
            </el-row>
          </div>
        </el-col>
        <el-col :span="8">
          <div class="grid-content bg-purple-3">
            <el-row>
              <el-col :span="10">
                <div style=" text-align: right">运行 <span style="font-size: 26px;">调度次数</span></div>
              </el-col>
              <el-col :span="14">
                <div style="line-height: 24px; margin-top: 48px;font-size: 18px;">
                  <span style="font-size: 20px; font-weight: bold; ">{{todayAgentExec}}</span> <!--/ {{yestDayAgentExec}}-->
                </div>
                <!--<div style="line-height: 24px;">今日/昨日</div>-->
              </el-col>
            </el-row>
          </div>
        </el-col>
      </el-row>
    </div>
    <div>
      <el-divider></el-divider>
    </div>
    <div style="margin: 42px 0 0 0 ">
      <h3>最新运行事件</h3>
      <el-table
        :data="dataList"
        border
        v-loading="dataListLoading"
        @selection-change="selectionChangeHandle"
        style="width: 100%;">
        <!--<el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>-->
        <el-table-column
          type="index"
          width="50"></el-table-column>
        <!--<el-table-column prop="id"  label="主键" header-align="center" align="center"></el-table-column>-->
        <!--<el-table-column prop="priorityLevel"  label="重要等级" header-align="center" align="center" width="100"></el-table-column>-->
        <!--<el-table-column prop="noticeTitle"  label="通知标题" header-align="center" align="center"></el-table-column>-->
        <el-table-column prop="noticeName"  label="通知名称" header-align="center" align="left">
          <template slot-scope="scope">
            <span v-if="scope.row.priorityLevel == '0'" style="">{{ scope.row.noticeName}}</span>
            <span v-if="scope.row.priorityLevel == '1'" style="color: #dd6161 ">{{ scope.row.noticeName}}</span>
          </template>
        </el-table-column>
        <!--<el-table-column prop="noticeContext"  label="通知内容" header-align="center" align="center"></el-table-column>-->
        <!--<el-table-column prop="relType"  label="关联数据类型" header-align="center" align="center"></el-table-column>
        <el-table-column prop="relId"  label="关联ID" header-align="center" align="center"></el-table-column>-->
        <el-table-column prop="createTime"  label="创建时间" header-align="center" align="center" width="180"></el-table-column>
        <!--<el-table-column prop="updateTime"  label="时间戳" header-align="center" align="center"></el-table-column>-->

        <el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <!--<el-button type="text" size="small" @click="modEntity(scope.row)">修改</el-button>-->
            <el-button type="text" size="small" @click="gotoNotices(scope.row)">更多</el-button>
            <!--<el-button type="text" size="small" @click="deleteEntity(scope.row.id)">删除</el-button>-->
          </template>
        </el-table-column>
      </el-table>
<!--      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="page"
        :page-sizes="[5, 10, 20]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>-->

    </div>
  </div>
</template>


<script>
  //import AddEntity from './agentExecLogList-add'

  export default {
    data() {
      return {
        isShow: false,
        batchAlive: 0,
        batchCount: 0,
        taskAlive:0,
        taskCount:0,
        agentAlive:0,
        agentCount:0,
        todayBatchExec:0,
        yestDayBatchExec:0,
        todayTaskExec:0,
        yestDayTaskExec:0,
        todayAgentExec:0,
        yestDayAgentExec:0,

        dataListLoading:false,
        searchForm: {},
        dataList: [],
        page: 1,
        pageSize: 5,
        totalPage: 0,
      }
    },
    components: {
      //AddEntity, ModEntity,
    },
    activated() {
      this.queryAll();
    },
    methods: {
      queryAll(){
        this.queryBatchCount();
        this.queryTaskCount();
        this.queryAgentCount();
        this.queryTodayBatch();
        this.queryTodayTask();
        this.queryTodayAgent();
        this.queryList();

      },
      // 获取数据列表
      queryBatchCount() {
        let obj = {}
        this.getTableList('/api/stat/batch-stat', obj, (data) => {
          if (data.code == '000000') {
            this.batchCount = data.count;
            this.batchAlive = data.alive;
          }
        })
      },
      queryTaskCount() {
        let obj = {}
        this.getTableList('/api/stat/task-stat', obj, (data) => {
          if (data.code == '000000') {
            this.taskCount = data.count;
            this.taskAlive = data.alive;
          }
        })
      },
      queryAgentCount() {
        let obj = {}
        this.getTableList('/api/stat/agent-stat', obj, (data) => {
          if (data.code == '000000') {
            this.agentCount = data.count;
            this.agentAlive = data.alive;
          }
        })
      },
      queryTodayBatch() {
        let obj = {}
        this.getTableList('/api/stat/today-batch-exec', obj, (data) => {
          if (data.code == '000000') {
            this.todayBatchExec = data.count;
            this.yestDayBatchExec = data.alive;
          }
        })
      },
      queryTodayTask() {
        let obj = {}
        this.getTableList('/api/stat/today-task-exec', obj, (data) => {
          if (data.code == '000000') {
            this.todayTaskExec = data.count;
            this.yestDayTaskExec = data.alive;
          }
        })
      },
      queryTodayAgent() {
        let obj = {}
        this.getTableList('/api/stat/today-agent-exec', obj, (data) => {
          if (data.code == '000000') {
            this.todayAgentExec = data.count;
            this.yestDayAgentExec = data.alive;
          }
        })
      },

      queryList(clr) {
        if (typeof (clr) != 'undefined') {
          this.page = 1
        }
        this.dataListLoading = true
        let obj = {
          'page': this.page,
          'size': this.pageSize,
        }
        obj = Object.assign(obj, this.searchForm)
        this.getTableList('/api/notice/list', obj, (data) => {
          this.dataListLoading = false
          setTimeout(this.queryAll, 60*1000);
          if (data.code == '000000' && data.rows && data.rows.length > 0) {
            this.dataList = data.rows
            this.totalPage = data.total
          } else {
            this.dataList = []
            this.totalPage = 0
          }
        })
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val
        this.page = 1
        this.queryList()
      },
      // 当前页
      currentChangeHandle(val) {
        this.page = val
        this.queryList()
      },
      // 多选
      selectionChangeHandle(val) {
        this.dataListSelections = val
      },
      gotoNotices(){
        this.$router.push({ name: 'biz-notice-list' , params: ''});
      },
    }
  }
</script>

<style>
  .mod-home {
    line-height: 110px;
    text-align: center;
  }

  .grid-content {

  }

  .font-size-l {
    font-size: 24px;
  }

  .bg-purple-1 {
    background: #ceddff;
  }

  .bg-purple-2 {
    background: #caf7ea;
  }

  .bg-purple-3 {
    background: #ffdfbf;
  }
</style>

